const path = require('path'),
      Uglify = require('uglifyjs-webpack-plugin'),
      Autoprefixer = require('autoprefixer'),
      MiniCssExtractPlugin = require('mini-css-extract-plugin'),
      OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');

const config = {
  performance: {

    hints: false

  },
  mode: 'production',
  entry: {
    shop_index: path.resolve(__dirname, './src/js/shop_index.js'),  //配置页面
    shop_detail: path.resolve(__dirname, './src/js/shop_detail.js'),
    // admin_add_edit_prod: path.resolve(__dirname, './src/js/admin_add_edit_prod.js'),  //打包有问题，放源未压缩的文件
    admin_manage_prod: path.resolve(__dirname, './src/js/admin_manage_prod.js'),
    404: path.resolve(__dirname, './src/js/404.js'),
    // jquery: path.resolve(__dirname, './src/js/jquery.min.js')
  },
  output: {
    path: path.resolve(__dirname + '/public'),
    filename: 'js/[name].js'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: [
          path.resolve(__dirname, 'node_modules')
        ]
      },

      {
        test: /\.tpl$/,
        loader: 'ejs-loader'
      },

      {
        test: /\.scss$/,
        use: [

          {
            loader: MiniCssExtractPlugin.loader,
            options: {
              hmr: process.env.NODE_ENV === 'development'
            }
          },

          'css-loader',

          {
            loader: 'postcss-loader',
            options: {
              plugin() {
                return [autoprefixer('last 5 versions')];
              }
            }
          },

          'sass-loader'
        ]
      },

      {
        test: /\.css$/,
        use: [

          {
            loader: MiniCssExtractPlugin.loader,
            options: {
              hmr: process.env.NODE_ENV === 'development'
            }
          },

          'css-loader',

          {
            loader: 'postcss-loader',
            options: {
              plugin() {
                return [autoprefixer('last 5 versions')];
              }
            }
          }
        ]
      },

      {
        test: /\.(png|jpg|jpeg|gif|ico)$/i,
        loader: [
          'url-loader?limit=2048&name=img/[name]-[hash:16].[ext]'
        ]
      },

      {
        test: /\.(woff2?|eot|ttf|oft|svg)(\?.*)?$/i,
        loader: [
          'url-loader?name=fonts/[name].[ext]'
        ]
      },
    ]
  },

  plugins: [
    new Uglify(),
    new OptimizeCssAssetsPlugin({}),
    new MiniCssExtractPlugin({
      filename: 'css/[name].css'
    })
  ],

  devServer: {
    watchOptions: {
      ignored: /node_modules/
    },
    host: 'localhost',
    port: 3300,
    // open: true
  }
}

module.exports = config;





